package cn.redcoral.messageplus.handler;

import cn.messageplus.core.annotation.MessagePlusHandler;
import cn.messageplus.core.message.request.ChatRequest;
import cn.messageplus.core.message.response.ChatResponse;
import cn.messageplus.core.util.MpcUtil;
import cn.redcoral.messageplus.port.MessagePlusUtil;
import cn.redcoral.messageplus.properties.MessagePlusMessageProperties;
import cn.redcoral.messageplus.utils.CounterIdentifierUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * 音频请求处理器
 **/
@Slf4j
@MessagePlusHandler
@ChannelHandler.Sharable
public class ChatHandler extends SimpleChannelInboundHandler<ChatRequest> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ChatRequest msg) throws Exception {
        // 1.创建响应对象
        ChatResponse chatResponse = new ChatResponse(msg.getContent());
        // 2.拷贝
        BeanUtils.copyProperties(msg, chatResponse);
        // 3.响应请求
        MpcUtil.send(chatResponse);
    }
}
